package com.yc.healthy.controller;


import com.yc.healthy.entity.Cuisine;
import com.yc.healthy.entity.Result;
import com.yc.healthy.mapper.CuisineMapper;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lyl
 * @since 2023-03-08
 */
@Controller
@RequestMapping("/healthy/cuisine")
public class CuisineController {

    @Resource
    CuisineMapper cuisineMapper;

    @PostMapping("querybytype")
    @ResponseBody
    public Result queryBytype(@RequestParam("type") String type){
        List<Cuisine> cuisines = cuisineMapper.SelectBytype(type);
        if (cuisines.isEmpty()){
            return new Result(0,"查无数据",null);
        }else {
            return new Result(1,"查询成功",cuisines);
        }

    }

    @PostMapping("querylikebyname")
    @ResponseBody
    public Result querylikeByname(String name){
        List<Cuisine> cs = cuisineMapper.SelectByname(name);
        if (cs.isEmpty()){
            return new Result(0,"查无数据",null);
        }else {
            return new Result(1,"查询成功",cs);
        }
    }

    @PostMapping("querybyId")
    @ResponseBody
    public Result queryByid( int id){
        Cuisine c = cuisineMapper.selectById(id);
        if ("".equals(c) || c == null){
            return new Result(0,"查无数据",null);
        }else {
            return new Result(1,"查询成功",c);
        }
    }
}

